home *** CD-ROM | disk | FTP | other *** search
/ Maplin Electronics Catalogue 2001 Winter / Maplins Catalogue Winter 2001.iso / JScript / checkout.js < prev    next >
Text File  |  2001-03-27  |  9KB  |  245 lines

  1. // Checkout.js JavaScript Development by Burgeonet.com
  2.  
  3. // ****Begin shopping cart functions.****
  4.  
  5. // ** global variables for the shopping cart.**
  6.  
  7. var itemNum = new Array();
  8. var itemDescr = new Array();
  9. var itemCost = new Array();
  10. var itemQty = new Array();
  11.                                        
  12.  
  13. // **Function to parse the cookie and extract the ordered **
  14. // **items from the string. This in turn triggers the **
  15. // **writeCart() function to display the shopping cart. **
  16.  
  17. function itemsOrdered() {
  18.  if (getCookieData("Scart")) {
  19.  substr0 = getCookieData("Scart")
  20.  cLen = substr0.length
  21.  offset0 = substr0.indexOf("@")
  22.  
  23.  counter = substr0.substring(0,offset0)
  24.  
  25.  j = 0
  26.   for (i=1; i<=counter; i++) {
  27.   offsetq = eval('offset' + j + '');
  28.   substrq = eval('substr' + j + '');
  29.  
  30.   eval('ind' + i + ' = offsetq + 1');
  31.   eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
  32.   eval('offset' + i + ' = substr' + i + '.indexOf("^")');
  33.   eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
  34.  
  35.   eval('catInd' + i + ' = item' + i + '.indexOf("`")');
  36.   eval('itemCat' + i + ' = item' + i + '.substring(0,catInd' + i + ')');
  37.  
  38.   eval('descrInd' + i + ' = item' + i + '.indexOf("~")');
  39.   eval('itemDes' + i + ' = item' + i + '.substring((catInd' + i + ' + 1),descrInd' + i + ')');
  40.  
  41.   eval('priceInd' + i + ' = item' + i + '.indexOf("½")');
  42.   eval('itemPr' + i + ' = item' + i + '.substring((descrInd' + i + ' + 2),priceInd' + i + ')'); 
  43.   
  44.   eval('itemQt' + i + ' = item' + i + '.substring((priceInd' + i + ' + 1),offset' + i + ')'); 
  45.   eval('orderDetail(i,itemCat' + i + ',itemDes' + i + ',itemPr' + i + ',itemQt' + i +')');
  46.  
  47.  
  48.   j++
  49.  
  50.  }
  51.  writecheckout();
  52.  }
  53. }
  54.  
  55. // **Builds an array of the items to load the cart.**
  56.  
  57. function orderDetail(seq,num,descr,cost,Qty) {
  58.  itemNum[seq]   = num
  59.  itemDescr[seq] = descr
  60.  itemCost[seq]  = cost
  61.  itemQty[seq]  = Qty
  62. }
  63.  
  64. // ** Function to write the shopping cart details **
  65. // ** into the table on the shopping cart page.
  66.  
  67.  
  68. function writecheckout() {
  69.  
  70.  var ordFrm  =  ' <BR> '
  71.  ordFrm +=  '     <FORM METHOD="post"'
  72.  ordFrm +=  '      ACTION="https://catalogue.maplin.co.uk/direct/CDEntry.asp" ID="form1"'
  73.  ordFrm +=  '    NAME="form1" Target="about:blank"> <INPUT TYPE="hidden" NAME="TotalItems" VALUE="' + counter + '"> '
  74.  ordFrm +=  '     <TABLE WIDTH="466" BGCOLOR="#000000" BORDER="1"BORDERCOLOR="#000096"'
  75.  ordFrm +=  '      CELLPADDING="0" CELLSPACING="0"> '
  76.  ordFrm +=  '        <TR> '
  77.  ordFrm +=  '          <TD BGCOLOR="#FFFFFF"> '
  78.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#000096" BORDER="0" CELLPADDING="0"'
  79.  ordFrm +=  '              CELLSPACING="0"> '
  80.  ordFrm +=  '                <TR VALIGN="TOP"> '
  81.  ordFrm +=  '                  <TD WIDTH="60" VALIGN="TOP" ALIGN="LEFT"><FONT'
  82.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1" COLOR="#FFFFFF">'
  83.  ordFrm +=  '                     <B> Order<BR> Code</B></FONT></TD> '
  84.  ordFrm +=  '                  <TD WIDTH="140" VALIGN="TOP" ALIGN="LEFT"><FONT'
  85.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1"'
  86.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Description</B></FONT></TD> '
  87.  ordFrm +=  '                  <TD COLSPAN="2" WIDTH="60" VALIGN="TOP" ALIGN="CENTER"><FONT'
  88.  ordFrm +=  '                     COLOR="#FFFFFF" FACE="verdana,Arial,helvetica" SIZE="1"><B>Qty</B></FONT></TD> '
  89.  ordFrm +=  '                  <TD WIDTH="70" VALIGN="TOP" ALIGN="RIGHT"><FONT'
  90.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1" COLOR="#FFFFFF"><B>inc.VAT'
  91.  ordFrm +=  '                     <BR>each</B></FONT></TD> '
  92.  ordFrm +=  '                  <TD WIDTH="60" ALIGN="RIGHT" VALIGN="TOP"><FONT'
  93.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="-2"'
  94.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Total</B></FONT></TD> '
  95.  ordFrm +=  '                  <TD VALIGN="TOP" ALIGN="CENTER" WIDTH="80"><FONT'
  96.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1"'
  97.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Remove</B></FONT></TD> '
  98.  ordFrm +=  '                </TR> '
  99.  ordFrm +=  '             </TABLE> '
  100.  
  101.  ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  102.  ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  103.  ordFrm +=  '                <TR> '
  104.  ordFrm +=  '                  <TD></TD> '
  105.  ordFrm +=  '                </TR> '
  106.  ordFrm +=  '             </TABLE> '
  107.  
  108.  
  109.   for (i = 1; i <= counter; i++) {
  110.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
  111.  ordFrm +=  '              CELLSPACING="0"> '
  112.  ordFrm +=  '                <TR> '
  113.  ordFrm +=  '                  <TD WIDTH="60"><FONT FACE="verdana,Arial,helvetica" SIZE="-2"'
  114.  ordFrm +=  '                     COLOR="#330099"><B> ' + itemNum[i] + '</B></FONT></TD> '
  115.  ordFrm +=  '                  <TD WIDTH="140"><FONT FACE="verdana,Arial,helvetica"'
  116.  ordFrm +=  '                     SIZE="-2">' + itemDescr[i] + '</FONT></TD> '
  117.  ordFrm +=  '                  <TD WIDTH="45" ALIGN="CENTER"><FONT'
  118.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1">' + itemQty[i] + '</FONT></TD> '
  119.  ordFrm +=  '                  <TD WIDTH="70" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  120.  ordFrm +=  '                     SIZE="-2">£' + itemCost[i] + '</FONT></TD> '
  121.  ordFrm +=  '                  <TD WIDTH="60" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  122.  ordFrm +=  '                     SIZE="-2">£' + fix(itemCost[i]  *  itemQty[i]) + '</FONT></TD> '
  123.  ordFrm +=  '                  <TD WIDTH="80" ALIGN="RIGHT"><A href="javascript:clearIt('+i+')"><IMG'
  124.  ordFrm +=  '                     SRC="remove.gif" WIDTH="60" HEIGHT="15" BORDER="0"></A></TD> '
  125.   
  126. ordFrm +=  '        <!-- Hidden Text Boxes to store code and quantity for submission -->'
  127.   ordFrm +=  '            <TR> '
  128.   ordFrm +=  '               <TD><INPUT TYPE="hidden" NAME="OrderCode' + i + '" MAXLENGTH="5" VALUE="' + itemNum[i] + '">'
  129.   ordFrm +=  '               <INPUT TYPE="hidden" NAME="Quantity' + i + '" MAXLENGTH="5" VALUE="' + itemQty[i] + '"> </TD> '
  130.   ordFrm +=  '            </TR> '
  131.   ordFrm +=  '        <!-- =========================================================== -->'
  132.  
  133.  ordFrm +=  '                </TR> '
  134.  ordFrm +=  '             </TABLE> '
  135.  
  136.   ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  137.   ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  138.   ordFrm +=  '                <TR> '
  139.   ordFrm +=  '                  <TD></TD> '
  140.   ordFrm +=  '                </TR> '
  141.   ordFrm +=  '             </TABLE> '
  142.  
  143.   }
  144.  
  145.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
  146.   ordFrm +=  '              CELLSPACING="0"> '
  147.   ordFrm +=  '                <TR> '
  148.   ordFrm +=  '                  <TD WIDTH="60"> </TD> '
  149.   ordFrm +=  '                  <TD WIDTH="140"><FONT FACE="verdana,Arial,helvetica"'
  150.   ordFrm +=  '                     SIZE="-2" COLOR="#006400">Total Items = ' + counter + '</FONT></TD> '
  151.   ordFrm +=  '                  <TD WIDTH="45" ALIGN="CENTER"> </TD> '
  152.   ordFrm +=  '                  <TD WIDTH="70" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  153.   ordFrm +=  '                     SIZE="-2" COLOR="#000066">Sub Total</FONT></TD> '
  154.   ordFrm +=  '                  <TD WIDTH="60" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  155.   ordFrm +=  '                     SIZE="-2">£' + update() + '</FONT></TD> '
  156.   ordFrm +=  '                  <TD WIDTH="80" ALIGN="RIGHT"> </TD> '
  157.   ordFrm +=  '                </TR> '
  158.  
  159.   ordFrm +=  '             </TABLE>'
  160.   ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  161.   ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  162.   ordFrm +=  '                <TR> '
  163.   ordFrm +=  '                  <TD></TD> '
  164.  
  165.  
  166.  ordFrm +=  '            </TABLE> '
  167.  ordFrm +=  '                <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
  168.  ordFrm +=  '         CELLSPACING="0"> '
  169.  ordFrm +=  '              <TR VALIGN="MIDDLE"> '
  170.  ordFrm +=  '                     <TD ALIGN="LEFT" VALIGN="MIDDLE" WIDTH="192"><A'
  171.  ordFrm +=  '                    HREF="javascript:history.go(-1)"><IMG SRC="return.gif" WIDTH="60" HEIGHT="15"'
  172.  ordFrm +=  '                        BORDER="0"></A></TD> '
  173.  ordFrm +=  '                     <TD ALIGN="CENTER" VALIGN="MIDDLE" WIDTH="82"> </TD> '
  174.  ordFrm +=  '                 <TD ALIGN="RIGHT" VALIGN="MIDDLE" WIDTH="192">'
  175.  ordFrm +=  '                    <INPUT TYPE="image" SRC="orderbtn.gif" Border="0"></TD> '
  176.  ordFrm +=  '          </TR> '
  177.  ordFrm +=  '        </TABLE> </TD> '
  178.  ordFrm +=  '        </TR> '
  179.  ordFrm +=  '     </TABLE>'
  180.  
  181.   ordFrm += '</form> '
  182.   document.write(ordFrm);
  183.   document.close();
  184. }
  185.  
  186. // ** Function to delete a line item upon user request. **
  187.  
  188. function clearIt(num) {
  189.  itemNum[num] = "item"
  190.  rewriteCookie(num)
  191. }
  192.  
  193. // **Function to rewrite the cookie when the user **
  194. // **deletes a line item from the shopping cart. **
  195.  
  196. function rewriteCookie(num) {
  197.  dataUpdate = ""
  198.  for (i=1; i<=counter; i++) {
  199.    if (itemNum[i] != "item") {
  200.     dataUpdate += itemNum[i] + '`' + itemDescr[i] + '~$' + itemCost[i] + '½' + itemQty[i] + '^'
  201.    }
  202.  }
  203.  counter = counter - 2
  204.  cookData = dataUpdate
  205.  setCookieData("Scart", cookData, expdate.toGMTString())
  206.  history.go(0)
  207. }
  208.  
  209. // ****End shopping cart detail section.****
  210.  
  211. // ****Start of code section to display subtotal.****
  212.  
  213. function update() {
  214.  if (getCookieData("Scart")) {
  215.   var sub_total = 0;
  216.   for (i=1; i<itemNum.length; i++)
  217.    eval('sub_total += parseFloat(itemCost[' + i + '] * itemQty[' + i + ']);');
  218.     //document.shopCart.subtotal.value= fix(sub_total);
  219.      return + fix(sub_total);
  220.  }
  221. }
  222.  
  223.  
  224. function fix(num) {
  225.  string = "" + num;
  226.  if (string.indexOf('.') == -1)
  227.   return string + '.00';
  228.  seperation = string.length - string.indexOf('.');
  229.  if (seperation > 3)
  230.   return string.substring(0,string.length-seperation+3);
  231.  else if (seperation == 2)
  232.   return string + '0';
  233.  return string;
  234. }
  235.  
  236. // **Function to clear the shopping cart.**
  237.  
  238. function killCart() {
  239.  killCookie("Scart")
  240.  history.go(-1)
  241. }
  242.  
  243.  
  244.  
  245.